<template>
	<view>
		<u-navbar title-color="#ffffff" title="我的红包" back-text="返回" back-icon-color="#ffffff" :back-text-style="textObj"
		 :border-bottom="false" :background="background"></u-navbar>
		<view class="main-mask">
			<view class="mask-box"></view>
		</view>
		<view class="main">
			<view class="box">
				<view class="">红包余额</view>
				<view class="">{{currentEnableFee}}</view>
			</view>
			<view class="box">
				<view class="">待分红包</view>
				<view class="">{{waitProceedMallFee}}</view>
				<view class="line"></view>
			</view>
		</view>
		<view class="container">
			<view class="content">
				<view class="title">
					<view class="left">
						<view v-for="(item,index) in type" :key="index" class="active">{{item}}
						</view>
					</view>
					<view class="right" @click="show = true">
						<text>{{currentDate}}</text>
						<u-icon size="18" name="arrow-down-fill" color="#E1E0E0"></u-icon>
					</view>
				</view>
				<view class="list">
					<view class="loading" v-if="list == '' && !fail">
						<u-loading mode="circle"></u-loading>
					</view>
					<view v-if="fail" style="padding-top: 300rpx;">
						<u-empty mode="list"></u-empty>
					</view>

					<view class="item" v-for="(item,index) in list" :key="index">
						<view class="other">
							<view class="">{{item.addTime}}</view>
							<view class="">共计：
								<text>{{item.totalAmount}}</text>
							</view>
						</view>
						<!-- <block v-if="typeIndex == 0">
							<view class="item-list" v-for="(items,indexs) in item.items" :key="indexs">
								<view>
									<view class="">
										订单号：{{items.payOrderNumber}}
									</view>
									<view class="">{{items.rebateTypeName}}</view>
								</view>
								<view class="">
									<view class="">{{items.addTime}}</view>
									<view class="">{{items.fee}}</view>
								</view>
							</view>
						</block> -->
						<view class="item-list" v-for="(items,indexs) in item.orderRebateList" :key="indexs">
							<view class="user">
								<u-image width="38rpx" height="38rpx" shape="circle" :src="items.joinUserHeadPhoto ? imageURL + items.joinUserHeadPhoto : appletImgUrl+'logo.png'"></u-image>
								<view class="name">{{items.joinUserNickName}}</view>
							</view>
							<view>
								<view class="">
									订单号：{{items.orderNumber}}
								</view>
								<view class="">{{items.typeName}}</view>
							</view>
							<view class="">
								<view class="">{{items.addTime}}</view>
								<view class="">{{items.amount}}</view>
							</view>
						</view>
					</view>

					<u-loadmore v-if="list != ''" :status="status"></u-loadmore>
					<u-gap></u-gap>
					<view class="safe-area-inset-bottom"></view>
				</view>
			</view>
		</view>

		<view class="btn" @click="approveStatus ? $u.route('/pages/user/withdrawal/withdrawal',{
			currentEnableFee:currentEnableFee,
			typeIndex:1
		}) : approvePopup = true">
			<view class="btn-box">
				提现
			</view>
			<view class="safe-area-inset-bottom"></view>
		</view>
		<u-picker mode="time" confirm-color="#FF4E47" @confirm="confirm" v-model="show" :params="params"></u-picker>
		<u-modal confirm-text="去认证" show-cancel-button confirm-color="#FF4D46" v-model="approvePopup" @confirm="$u.route('/pages/user/realName/realName',{
			realState:realState
		})"
		 content="您得先实名认证了才可以提现"></u-modal>
	</view>
</template>

<script>
import {appletImgUrl} from "@/common/config.js"
	let uTabOffsetTop = 44 + uni.getSystemInfoSync().statusBarHeight
	export default {
		data() {
			return {
				appletImgUrl:appletImgUrl,
				current: 0,
				approveStatus: false,
				realState:"",
				type: ['红包明细'],
				imageURL: this.imageURL,
				status: 'loading',
				approvePopup: false,
				params: {
					year: true,
					month: true
				},
				show: false,
				currentEnableFee: 0,
				waitProceedMallFee: 0,
				// list: [{
				// 	name: '线上'
				// }, {
				// 	name: '线下'
				// }],
				textObj: {
					color: '#ffffff'
				},
				list: [],
				fail: false,
				currentDate: '',
				background: {
					backgroundImage: 'linear-gradient(90deg, #FD3129, #FF4D46)'
				}
			};
		},
		onLoad() {
			this.pageNo = 1
			this.$u.get('userwallet/info').then(res => {
				this.currentEnableFee = res.currentEnableFee
				this.waitProceedMallFee = res.waitProceedMallFee
			})


			this.$u.get('userverify/ok').then(res => {
				switch (res.approveStatus) {
					case 20:
						this.approveStatus = true
						break
					case 10:
						this.realState = 1
						break
				}
				if (!res.approveStatus) {
					this.realState = 0
				}
			})



			var date = new Date();
			var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
			var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
			let c = new Date(date)
			let cdate = c.getFullYear() + '-' + (c.getMonth() + 1)
			this.currentDate = cdate

			var f = new Date(firstDay);
			var firstDatetime = f.getFullYear() + '-' + (f.getMonth() + 1) + '-' + f.getDate();

			var l = new Date(lastDay);
			var lastDatetime = l.getFullYear() + '-' + (l.getMonth() + 1) + '-' + l.getDate();

			this.firstDatetime = firstDatetime
			this.lastDatetime = lastDatetime
			this.getList(firstDatetime, lastDatetime, res => {
				this.status = res.length < 10 ? 'nomore' : 'loadmore'
			})
		},
		onPageScroll({
			scrollTop
		}) {
			var opacity = 0,
				maxNumber = uTabOffsetTop
			if (scrollTop <= maxNumber) {
				opacity = scrollTop / maxNumber
			} else {
				opacity = 1
			}
			if (opacity == this.opacity) return
			this.background.backgroundColor = `rgba(254,70,102,${opacity})`
		},
		onReachBottom() {
			if (this.status == 'loading' || this.status == 'nomore') return
			this.pageNo++
			this.status = 'loading'
			this.getList(this.firstDatetime, this.lastDatetime, res => {
				if (res == '') {
					this.status = 'nomore'
					return
				}
				this.status = 'loadmore'
			})
		},
		methods: {
			getList(startTime, endTime, fn = () => {}) {
				this.$u.post('groupbuyinglist/getRebateInfo', {
					endTime: endTime,
					startTime: startTime,
					pageNo: this.pageNo,
					pageSize: 10
				}).then(res => {
					if (res.list == '') {
						this.fail = true
						fn([])
						return
					}
					fn(res.list)
					this.list = this.list.concat(res.list)
				}).catch(error => {
					this.fail = true
				})
			},
			confirm(e) {
				var firstDay = new Date(e.year, e.month, 1);
				var lastDay = new Date(e.year, e.month, 0);
				var f = new Date(firstDay);
				let year = e.month == '12' ? f.getFullYear() - 1 : f.getFullYear()
				let month = e.month == '12' ? 12 : f.getMonth()
				var firstDatetime = year + '-' + month + '-' + f.getDate();
				var l = new Date(lastDay);
				var lastDatetime = l.getFullYear() + '-' + (l.getMonth() + 1) + '-' + l.getDate();
				this.currentDate = `${e.year}-${e.month}`
				this.firstDatetime = firstDatetime
				this.lastDatetime = lastDatetime
				this.pageNo = 1
				this.fail = false
				this.list = []
				this.status = 'loading'
				this.getList(firstDatetime, lastDatetime, res => {
					this.status = res.length < 10 ? 'nomore' : 'loadmore'
				})
			}
		}
	}
</script>

<style lang="scss">
	.btn {
		position: fixed;
		width: 100%;
		bottom: 0;
		z-index: 2;
		left: 0;
		background: linear-gradient(90deg, #FD3129, #FF4D46);
		border-radius: 40rpx 40rpx 0 0;
		.btn-box {
			line-height: 100rpx;
			color: #FFFFFF;
			text-align: center;
			font-size: 28rpx;
		}
	}

	.container {
		position: relative;
		z-index: 1;
		top: -35rpx;

		.content {
			border-radius: 40rpx 40rpx 0px 0px;
			background-color: #FFFFFF;
			padding: 0 30rpx;

			.list {
				padding-bottom: 65rpx;

				.loading {
					display: flex;
					justify-content: center;
					padding-top: 300rpx;
				}

				.item {
					border-top: 1rpx solid #E1E0E0;
					padding: 30rpx 0;

					&:first-child {
						border-top: none;
					}

					.item-list {
						margin-top: 30rpx;

						>view {
							display: flex;
							margin-top: 5rpx;
							align-items: center;
							justify-content: space-between;
						}

						.user {
							justify-content: flex-start;
							margin-bottom: 25rpx;

							.name {
								margin-left: 15rpx;
							}
						}
					}

					.other {
						display: flex;
						align-items: center;
						justify-content: space-between;

						view {
							&:first-child {
								font-weight: bold;
								font-size: 28rpx;
							}

							&:last-child {
								text {
									color: #FF4D46;
									font-size: 48rpx;
									font-weight: bold;
								}
							}
						}
					}
				}
			}

			// .money {
			// 	view {
			// 		&:first-child {
			// 			font-size: 24rpx;
			// 		}

			// 		&:last-child {
			// 			font-weight: bold;
			// 			font-size: 30rpx;

			// 			text {
			// 				font-size: 48rpx;
			// 			}
			// 		}
			// 	}
			// }

			.tab {
				height: 82rpx;
				border-bottom: 1rpx solid #E1E0E0;
			}

			.title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 45rpx 0;
				border-bottom: 1rpx solid #E1E0E0;

				.right {
					&:last-child {
						padding: 5rpx 15rpx;
						display: flex;
						border: 1rpx solid #E1E0E0;
						border-radius: 4rpx;
						align-items: center;

						text {
							margin-right: 10rpx;
						}
					}

					&:first-child {
						font-weight: bold;
						font-size: 32rpx;
					}
				}

				.left {
					display: flex;
					align-items: center;

					>view {
						color: #AAAAAA;
						position: relative;

						.icon {
							position: absolute;
							bottom: -58rpx;
							left: 50%;
							transform: translateX(-50%);
						}

						&.active {
							font-size: 36rpx;
							color: #000000;
							font-weight: bold;
						}

						&:last-child {
							// margin-left: 40rpx;
						}
					}
				}
			}
		}
	}

	.main-mask {
		background: linear-gradient(90deg, #FD3129, #FF4D46);
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		height: 50%;
	}

	.main {
		display: flex;

		.box {
			text-align: center;
			padding-bottom: 75rpx;
			padding-top: 30rpx;
			flex: 1;
			position: relative;

			.line {
				position: absolute;
				top: 50%;
				left: 0;
				transform: translateY(-50%);
				width: 1rpx;
				height: 65rpx;
				background-color: rgba($color: #ffffff, $alpha: .5);
				margin-top: -20rpx;
			}

			view {
				color: #FFFFFF;

				&:first-child {
					font-size: 24rpx;
				}

				&:nth-child(2) {
					font-size: 60rpx;
					font-weight: bold;
					// margin: 10rpx 0;
					margin-top: 5rpx;
					// margin-bottom: 15rpx;
				}

				// &:last-child {
				// 	display: flex;
				// 	justify-content: center;

				// 	navigator {
				// 		font-size: 24rpx;
				// 		border: 1rpx solid #FFFFFF;
				// 		color: #FFFFFF;
				// 		line-height: 56rpx;
				// 		border-radius: 10rpx;
				// 		// width: 170rpx;
				// 		padding: 0 60rpx;
				// 	}
				// }
			}
		}
	}
</style>
